// conversation.js
import { http } from '../../server/http.server'
import { httpRouter } from '../../server/http.router'
import tempObj from '../template/template';
import { _ } from '../../libs/underscore/underscore.modified';
import { location } from '../../server/location';
import { coordinate } from '../../server/coordinate';

var bmap = require('../../libs/bmap-wx.min.js');
var wxMarkerData = [];
let interval;
var app = getApp();
let demoIndex = 0;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    guidesInfo: [],
    guidesList: [],
    cityId: '',
    userMsg: '',
    userMsgList: [],
    templateSelect: [],
    scrollTop: 0,//scrollTop 距离顶部距离
    show: false,//随便讲讲周边是否隐藏
    ShowStatus: false,
    guidesshow: "",
    audioList: [],
    freeList:[],
    location: [],
    playIndex: 0,
    templateIndex:0,
    SpotId: "",
    lng:0,
    lat:0,
    one: true,
    historyList:[],
    oldList:[],
    currentVoice:[],
    playStatus: "iconPause",//播放／暂停
    confirmStatus: false,
    scrollStatus: false,
    JiangIndex: 0,//讲讲身边信息当前的下标
    isBei: false,
    swiperCurrent: 0,
    success: false,
    btnStatus: false,
    timerStatus:false,
    loadStatus: true,
    timeStatus:false,
    againIndex:0,
    bublleStatus:false,
    voiceViewType:"voice",
    voiceContentTime:0
  },
  onShareAppMessage: function (res) {
    return {
      title: 'Ai导游',
      path: '/pages/index/index',
      success: function (res) { },
      fail: function (res) { }
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.audioCtx = wx.createAudioContext('myAudio');
    // 加载个人信息
    this.setData({
      cityId: app.globalData.city.CityId
    });
    // let user = app.globalData.userInfo;
    let cityId = app.globalData.city.CityId;
    //获取导游面信息
    this.GetGuidesInfo(cityId);

    this.data.location = app.data.location;

    this.setData({
      placeholder: "随便讲讲周边",
      userMsgList: ['讲讲故宫', '随便讲讲周边', '附近有什么好玩', '北京两日游攻略', '北京大学到颐和园怎么坐车', '北京大学', '雍和宫在哪里', '北京烤鸭']
    })
  },

  //获取导游信息
  GetGuidesInfo: function (cityId) {
    let that = this;
    let index = tempObj.Sui();
    let userId = app.data.userInfo.UserId;
    http.get(httpRouter.cityGuideList(cityId, userId)).subscribe({
      next: res => {
        let Content = res.data.Content.Guides[0];
        this.setData({
          guidesInfo: Content,
          guidesList: res.data.Content.Guides
        })
        //获取主页面信息
        this.getSpots(cityId);
      },
      error: err => {}
    })
  },
  closedGuide: function () {

    if (this.data.guidesshow == "") {
      this.setData({
        guidesshow: "db"
      })
    } else {
      this.setData({
        guidesshow: ""
      })
    }
  },
  //清空用户输入框
  clear: function () {
    this.setData({
      placeholder: ""
    })
  },
  //线路查询位置互换
  ExchangeRoute: function (e) {
    let index = e.currentTarget.dataset.length;//赋值
    let FromPlace = e.currentTarget.dataset.from;//赋值
    let ToPlace = e.currentTarget.dataset.to;//赋值
    let templatedata = this.data.templateSelect;
    templatedata[index].Content.FromPlace = ToPlace;
    templatedata[index].Content.ToPlace = FromPlace;
    this.setData({
      templateSelect: templatedata
    })
  },
  // 清空从到到哪
  clearRoute: function (e) {
    let index = e.currentTarget.dataset.length;//赋值
    let route = e.currentTarget.dataset.route;//赋值
    let templatedata = this.data.templateSelect;
    if (route == "to") {
      templatedata[index].Content.ToPlace = "";
    } else {
      templatedata[index].Content.FromPlace = "";
    }
    this.setData({
      templateSelect: templatedata
    })
  },
  //下拉显示／隐藏
  MsgListToggle: function () {
    if (this.data.ShowStatus) {
      this.setData({
        ShowStatus: false,
        scrollTop: this.data.scrollTop - 104,
      })
    } else {
      this.setData({
        ShowStatus: true,
        scrollTop: this.data.scrollTop + 104,
      })
    }
  },
  //下拉发送
  MsgSend: function (e) {
    this.userMsgList
    this.MsgListToggle();
    this.data.userMsg = e.currentTarget.dataset.msg;//赋值
    this.sendOut();
  },

  /**
   * 获取景区列表
   */
  getSpots: function (cityId) {
    let that = this;
    let url = httpRouter.spotList(cityId);
    http.get(url).subscribe({
      next: (res) => {
        let spotData = tempObj.format(res.data.Content.HotSpots);
        this.dataSetIn(spotData, "scenic-list", 0);
        that.setData({
          loadStatus: false
        });
      },
      error: err => {}
    })
  },
  //查询参数
  userMsg: function (e) {
    this.data.userMsg = e.detail.value || '随便讲讲周边';//赋值
  },
  //数据请求
  sendOut: function (e) {
    let again = e ? e.currentTarget.dataset.again : false;
    let that = this;
    if (this.data.userMsg == "") {
      this.data.userMsg = "随便讲讲周边";
    }
    this.data.userMsgList.unshift(this.data.userMsg);
    let newlist = _.uniq(this.data.userMsgList);
    if (this.data.userMsgList.length > 15) {
      newlist = newlist.slice(0, 15);
    }

    this.setData({
      placeholder: "随便讲讲周边",
      value: "",
      oldList:[],
      userMsgList: newlist
    })
    let ResultJson = [];//请求返回值
    let content = [];//请求返回值
    this.data.userMsg = (this.data.userMsg == "" ? "随便讲讲周边" : this.data.userMsg);
    if (again == "true" ){
      let i = this.data.templateSelect.length - 1;
      this.data.templateSelect[i].Content.SendStatus = "";
    }else{
      this.userInput(this.data.userMsg);
    }
   

    ///方法请求
    http.get(httpRouter.getMessagesUrl({
      query: this.data.userMsg,
      cityId: this.data.cityId,
      currentCityId: this.data.cityId,
      guideId: this.data.guidesInfo.GuideId,
      userId: app.data.userInfo.UserId,
      lat: app.data.location.lat,
      lng: app.data.location.lng,
      //lat: "39.914007360653535",
      //lng: "116.39726168392545",
      version: 4
    })).subscribe({
      next: res => {
        that.setData({
          userMsg: ''
        });
        ResultJson = res.data;//赋值
        that.data.timerStatus=false;
        that.sendSuc();

        switch (ResultJson.Type) {
          //
          case 1:
            that.data.timerStatus = true;
            content = JSON.parse(ResultJson.Content);
            that.homefreetime();
            that.setData({
              voiceViewType: "voiceBei",
            });
            break;
          case 2:
            //给我讲
            content = JSON.parse(ResultJson.Content).Contents;
            that.voice(content);
            that.setData({
              voiceViewType: "voice",
            });
            break;
          case 3:
            //北京一日游
            content = JSON.parse(ResultJson.Content);
            that.Onedaytravel(content)
            break;
          
          case 10:
            //天气加载
            let result = JSON.parse(ResultJson.Content);
            that.getCityWeather(result);
            break;
          case 12:
            //故宫到天坛 
            content = JSON.parse(ResultJson.Content);
            that.AddressSearch(content);
            break;
          case 13:
            that.SeyMessage("想要体验更多丰富的功能，请下载Ai导游APP");
            break;
          case 14:
            //反馈一段话
            that.SeyMessage(ResultJson.Content);
            break;
          case 15:
            //故宫在哪
            content = JSON.parse(ResultJson.Content);
            let gcj = coordinate.wgs84togcj02(content.Lng, content.Lat);
            content.Lng=gcj[0];
            content.Lat=gcj[1];
            that.Address(content);
            break;
          case 16:
            //天坛公园
            content = JSON.parse(ResultJson.Content);
            that.strategy(content);
            break;
          case 17:
            //附近景点
            content = JSON.parse(ResultJson.Content);
            that.NearScenics(content)
            break;
          case 19:
            //故宫游玩路线
            content = JSON.parse(ResultJson.Content);
            that.travelLine(content);
            break;
          case 21:
            that.SeyMessage("想要体验更多丰富的功能，请下载Ai导游APP");
            break;
          case 22:
            //错误
            content = JSON.parse(ResultJson.Content);
            that.err(content);
            break;
          case 23:
            //讲讲身边
            content = JSON.parse(ResultJson.Content);
            that.jiang(content);
            break;
          default:
            content = JSON.parse(ResultJson.Content);
            that.SeyMessage(ResultJson.Content);
            break;
        }
      },
      error: err => {
        that.sendfail();
        that.setData({
          templateSelect: that.data.templateSelect
        })
      }
    })
  },
  //用户输入显示
  userInput: function (userMsg) {
    this.audioCtx = wx.createAudioContext('myAudio');
    this.audioCtx.pause();
    let index = this.data.templateSelect.length - 1;//赋值
    this.data.templateSelect[index].playStatus = false;
    this.data.playStatus = "iconPause"
    this.setData({
      playStatus: this.data.playStatus
    })
    let Content = {
      userMsg: userMsg,
      SendStatus: "circle"
    };
    this.dataSetIn(Content, "user", 142);
  },
  //小艾绘回话
  SeyMessage: function (Content) {

    this.dataSetIn(Content, "bubble", 706);
  },
  // 地址
  Address: function (Content) {
    this.data.markers = [{
      id: 0
      , iconPath: "../../images/point.png"
      , longitude: Content.Lng
      , latitude: Content.Lat
      , width: 30
      , height: 30
    }]
    this.dataSetIn(Content, "address", 365);
  },
  // 地址查询
  AddressSearch: function (Content) {
    this.dataSetIn(Content, "route-query", 172);
  },
  // 旅游线路
  travelLine: function (Content) {
    this.dataSetIn(Content, "route", 220);
  },
  // 一日游
  Onedaytravel: function (Content) {
    this.dataSetIn(Content, "strategy-min", 500);
  },
  // 附近景点
  NearScenics: function (Content) {
    let spotData = tempObj.format(Content.Spots);
    Content.Spots = spotData;
    this.dataSetIn(Content, "min-scenics", 500);
  },
  strategy: function (Content) {
    this.dataSetIn(Content, "img-strategy", 193);
  },
  // 错误
  err: function (Content) {
    let random = Math.floor(Math.random() * 10);;
    let Msg = Content[random];
    this.dataSetIn(Msg, "bubble", 500);
  },
  sendSuc: function () {
    let i = this.data.templateSelect.length - 1;
    this.data.templateSelect[i].Content.SendStatus = "Suc";
  },
  sendfail: function () {
    let i = this.data.templateSelect.length - 1;
    this.data.templateSelect[i].Content.SendStatus = "fail";
  },
  jiang: function (Content) {
    this.dataSetIn(Content[this.data.JiangIndex], "jiang", 266);
    if (Content.length - 1 == this.data.JiangIndex) {
      this.data.JiangIndex = 0;
    } else {
      this.data.JiangIndex = this.data.JiangIndex + 1;
    }
  },

  //语音播报开始
  voice: function (Content) {
    this.dataSetIn("提示：共有讲解" + Content.length + "条，点跳过按钮可切换下一条", "hint", 106);
    this.dataSetIn("好的，请您稍等一下", "bubble", 106);
    this.data.isBei = false;

    this.SeacherVoice(Content);
  },
  //讲解查询
  SeacherVoice: function (Content) {
    let list = _.sortBy(Content, function (item) {
      return -item.ContentRelationLevel;
    });
   
    this.data.audioList = list;

    this.dataSetIn(this.data.audioList[0], "voice", 600);
    this.setData({
     
      lng: this.data.location.lng,
      lat: this.data.location.lat
    })
    this.VidoPlay();
  },
  //首页空闲时讲解
  homefreetime: function () {
    let lat = this.data.location.lat;
    let lng = this.data.location.lng;
    let cityId = this.data.cityId;
    let guideId = this.data.guidesInfo.GuideId;//导游ID
    let that = this;
    this.data.markers = [{
      id: 0, 
      iconPath: "../../images/point.png", 
      longitude: this.data.location.lng, 
      latitude: this.data.location.lat, 
      width: 30, 
      height: 30
    }]
    http.get(httpRouter.homefree(cityId, lat, lng, guideId)).subscribe({
      next: res => {
        that.data.freeList = res.data.Content;
        location.get().subscribe({
          next: res => {
            that.homePassive(res.latitude, res.longitude);//景区ID
          },
          error: err => {}
        });
      },
      error: err => {}
    })
  },
  homePassive: function (lat,lng) {
    let that = this;
    let url = httpRouter.homepassive2(this.data.cityId, lat, lng, this.data.guidesInfo.GuideId);
    http.get(url).subscribe({
      next: res => {
        let list = _.union(this.data.freeList, res.data.Content);
        list = _.sortBy(list, item => {
          return -item.ContentRelationLevel;
        });
        that.setData({
          audioList: list,
          isBei: true,
          lat: lat,
          lng: lng
        });
        let voice = that.data.audioList[0];
        voice.timeStatus = false;
        that.dataSetIn(voice, "voiceBei", 600);
        that.VidoPlay();
        that.passive()
      },
      error: err => {}
    })
  },


  //循环加载
  passive: function () {
    let that = this;
    interval = setInterval(function () {
      if (that.data.timerStatus) {
        that.getLocation();
      }
    }, 15000);
  },
  //获取播报
  getLocation: function () {
    let that = this;
    location.get().subscribe({
      next: res => {
        that.getPassive(res.latitude, res.longitude);//景区ID
       
      },
      error: err => {}
    });
  },
  /**
   * 景区被动讲解
   */
  getPassive: function (lat, lng) {
    let that = this;
    let url = httpRouter.homepassive2(this.data.cityId, lat, lng, this.data.guidesInfo.GuideId);
    http.get(url).subscribe({
      next: res => {
        that.mergeSpotVoice(res.data.Content);
        that.setData({
          lat: lat,
          lng: lng
        });
      },
      error: err => {}
    })
  },

  mergeSpotVoice: function (passiveList) {
    let list = _.union(this.data.freeList, passiveList);
    list = _.sortBy(list, item => {
      return -item.ContentRelationLevel;
    });
    list = this.mergeArray(list, this.data.historyList);
    list = this.mergeArray(list, this.data.oldList);
    list = this.mergeArray(list, this.data.currentVoice);
    this.data.audioList.splice(1, this.data.audioList.length);  
    this.data.audioList = _.union(this.data.audioList, list);
    if(this.data.playEnd && this.data.audioList.length>0){
      this.againPlay(this.data.againIndex)
      this.setData({
        playEnd: false
      })
    }
  },


  //合并数组
  mergeArray: function (array, filters) {

    try {
      if (array.length <= 0 && filters.length <= 0) {
        return array;
      }
      for (let i = 0; i < array.length; i++) {
        for (let j = 0; j < filters.length; j++) {
          if (filters[j] == null || !filters[j].ContentId) {

          }
          if (array[i].ContentId == filters[j].ContentId) {
            array.splice(i, 1);
          }
        }
      }
    } catch (err) {

    }


    return array;
  },

  //拆分数组
  chunk: function (list, index) {
    return {
      before: index < 0 ? [] : list.slice(0, index + 1),
      current: list.slice(index, index + 1),
      after: list.slice(index + 1)
    }
  },
  
  //播放
  VidoPlay: function () {
    this.audioCtx = wx.createAudioContext('myAudio');
    this.data.currentVoice = [this.data.audioList[0]];
    this.audioCtx.setSrc(this.data.audioList[0].ContentUri);
    this.data.voiceContentTime = parseFloat(this.data.audioList[0].ContentTimeSpan || 0);
    this.audioCtx.play();
    if (this.data.playStatus == "iconPause") {
      this.data.playStatus = "iconPause";
      this.setData({
        playStatus: this.data.playStatus,
        audioindex: this.data.templateSelect.length - 1
      })
    } else {
      this.data.playStatus = "iconPlay";
      this.setData({
        playStatus: this.data.playStatus,
        audioindex: this.data.templateSelect.length - 1

      })
    }
  },
  //暂停
  VidoPause: function (e) {
    let index = e.currentTarget.dataset.length;//赋值
    this.audioCtx = wx.createAudioContext('myAudio');

    if (this.data.playStatus == "iconPause") {
      this.data.playStatus = "iconPlay";
      this.setData({
        playStatus: this.data.playStatus,
        timeStatus:true
      })
      this.audioCtx.pause();

    } else {
      this.data.playStatus = "iconPause";
      this.audioCtx.play();
      this.setData({
        playStatus: this.data.playStatus,
        timeStatus:false
      })
    }
  },
  //播放时间
  audioTime: function (e) {
    let index = e.currentTarget.dataset.length;//赋值
    let type = e.currentTarget.dataset.type;//赋值
    let templatedata = this.data.templateSelect;
    let duration = this.data.voiceContentTime;
    templatedata[index].Content.ContentTimeSpan = tempObj.secondToMin(duration - e.detail.currentTime);
    templatedata[index].Content.timeStatus = true;
    this.setData({
      templateSelect: this.data.templateSelect,
      audioindex: this.data.templateSelect.length - 1
    })
  },
  //播放完，下一个
  againPlay: function (index) {
    this.audioCtx = wx.createAudioContext('myAudio');
    this.setData({
      timeStatus: false,
      againIndex: index
    });
    let current = this.data.audioList[0];
    this.data.playStatus = "iconPause";
    if (this.data.audioList.length > 0) {
      if (this.data.audioList.length == 0) {
        this.data.templateSelect[index].playStatus = true;
      } else {
        this.data.templateSelect[index].playStatus = false;
      }
      if (this.data.isBei) {
        this.data.templateSelect[index].Content = current;
        this.setData({
          templateSelect: this.data.templateSelect
        })
      } else {
        let voice = current;
        voice.timeStatus = false;
        this.dataSetIn(voice, "voiceBei", 600);
      }
      this.setData({
        playStatus: this.data.playStatus
      });
      this.data.currentVoice = [current];
      this.audioCtx.setSrc(current.ContentUri);
      this.data.voiceContentTime = parseFloat(this.data.audioList[0].ContentTimeSpan || 0);
      this.audioCtx.play();
    } else {
      this.showBublle();
      this.audioCtx.pause();
      this.setData({
        playEnd: true
      })
    }
  },
  //播放完，下一个
  audioEnd: function (e) {
    this.audioCtx = wx.createAudioContext('myAudio');
    let index = e.currentTarget.dataset.length;//赋值
    let type = e.currentTarget.dataset.type;//赋值
    this.setData({
      timeStatus: false,
      againIndex: index
    });
    let current = this.data.audioList[0];
    if(this.data.audioList.length > 0){
      this.data.oldList.push(current);
      tempObj.baoremove(this.data.audioList, 0);//总列表删除
    }
    this.data.playStatus = "iconPause";
    if (this.data.audioList.length > 0) {
      if (this.data.audioList.length == 0) {
        this.data.templateSelect[index].playStatus = true;
      } else {
        this.data.templateSelect[index].playStatus = false;
      }
      if (this.data.isBei) {
        this.data.templateSelect[index].Content = this.data.audioList[0];
        this.setData({
          templateSelect: this.data.templateSelect
        })
      } else {
        let voice = this.data.audioList[0];
        voice.timeStatus = false;
        
        this.dataSetIn(voice, type , 600);
        this.setData({
          audioindex: this.data.templateSelect.length - 1
        })
      }
      this.setData({
        playStatus: this.data.playStatus
      });
      this.data.currentVoice = [this.data.audioList[0]];
      this.audioCtx.setSrc(this.data.audioList[0].ContentUri);
      this.data.voiceContentTime = parseFloat(this.data.audioList[0].ContentTimeSpan || 0);
      this.audioCtx.play();
    }else{
      this.showBublle();
      //this.audioCtx.pause();
      this.setData({
        playEnd: true
      })
    }
  },
  voiceEnd: function (e) {
    this.audioCtx = wx.createAudioContext('myAudio');
    let index = e.currentTarget.dataset.length;//赋值
    this.setData({
      timeStatus: false,
      againIndex: index
    });
    
    let current = this.data.audioList[0];
    if(this.data.audioList.length > 0){
      this.data.historyList.push(current);
       tempObj.baoremove(this.data.audioList, 0);//总列表删除
    }
    this.data.playStatus = "iconPause";
    if (this.data.audioList.length > 0) {
      
      if (this.data.audioList.length == 0) {
        this.data.templateSelect[index].playStatus = true;
      } else {
        this.data.templateSelect[index].playStatus = false;
      }
      if (this.data.isBei) {
        this.data.templateSelect[index].Content = this.data.audioList[0];
        this.setData({
          templateSelect: this.data.templateSelect
        })
      } else {
        let voice = this.data.audioList[0];
        voice.timeStatus = false;
        
        this.dataSetIn(voice, this.data.voiceViewType, 600);
        this.setData({
          audioindex: this.data.templateSelect.length - 1
        })
      }
      this.setData({
        playStatus: this.data.playStatus
      })
      this.data.currentVoice = [this.data.audioList[0]];
      this.audioCtx.setSrc(this.data.audioList[0].ContentUri);
      this.data.voiceContentTime = parseFloat(this.data.audioList[0].ContentTimeSpan || 0);
      this.audioCtx.play();
    } else {
      this.showBublle();
      this.audioCtx.pause();
      this.setData({
        playEnd: true
      })
    }
  },
  showBublle:function(){
    this.setData({
      bublleStatus:true
    });
    setTimeout(()=>{
      this.setData({
        bublleStatus: false
      });
    },3000);
  },
  MoerContent: function (e) {
    let index = e.currentTarget.dataset.length;//赋值
    let templatedata = this.data.templateSelect;
    if (templatedata[index].More){
      templatedata[index].More = false;
      
    }else{
      templatedata[index].More = true;
    }

    this.setData({
      templateSelect: this.data.templateSelect
    })
    this.data.scrollTop = this.data.scrollTop + 200;
   
    this.setData({
      scrollTop: this.data.scrollTop
    })
  },
  SendAgin: function (e) {
    let SendStatus = e.currentTarget.dataset.sendstatus;//赋值
    let userMsg = e.currentTarget.dataset.usermsg;//赋值

    if (SendStatus == "fail") {
      this.data.userMsg = userMsg;
      this.sendOut();
    }
  },

  // 数据传人界面
  dataSetIn: function (Content, templateName, scrollTop) {
    this.data.templateSelect.push({
      Content: Content,
      selettype: templateName,
      userInfo: app.globalData.userInfo,
      guidesInfo: this.data.guidesInfo,
      playStatus: true,
      markers: this.data.markers,
      More: false,
    });
    if (this.data.templateSelect.length == 2) {
      this.data.scrollTop = this.data.scrollTop + 192 + scrollTop
    } else {
      this.data.scrollTop = this.data.scrollTop + scrollTop
    }
    this.setData({
      templateSelect: this.data.templateSelect,
      templateIndex: this.data.templateSelect.length-1,
      scrollTop: this.data.scrollTop
    })
    

  },
  //当前城市加载
  getCityWeatherByString: function () {
    //城市名称
    let CityName = "";
    let that = this;
    // 新建百度地图对象 
    let BMap = new bmap.BMapWX({
      ak: 'h9eT53k8znwXawZeF6KnItPT1KDxSi53'
    });
    // 发起regeocoding检索请求 
    BMap.regeocoding({
      success: function (data) {
        CityName = data.originalData.result.addressComponent.city;
        that.getCityWeather(CityName);
      }
    });
  },
  //免费天气接口获取城市3-7天天气信息
  getCityWeather: function (city) {
    http.get(httpRouter.CityWeather(city.CityName)).subscribe({
      next: res => {
        this.filterimg(res.data.HeWeather5[0], city.DateValue);
      },
      error: err => {}
    })
  },
  //天气信息传递到界面
 filterimg: function (weather,dateVal) {
    //根据天气代码加载不同class
    let flag = false;
    

    let date = new Date(dateVal);//当前时间
    let show_day = new Array('周日', '周一', '周二', '周三', '周四', '周五', '周六');
    let x = date.getDay();
    let weekday = show_day[x];//星期加载
    let list = _.clone(weather.daily_forecast);

    let current = _.find(list, function (item) {
      if (item.date == dateVal) {
        let nowdate = tempObj.crtTimeFtt(new Date(), "yyyy-MM-dd");
        item.today = (nowdate == dateVal) ? true　: false;
        item.ctmp = weather.now.tmp;
        return item;
      }
    }) || list[0];

    var code = current.cond.code_d;
    if (code == 100 || code == 103 || code == 900 || code == 999) {
      flag = false;
    } else if (code >= 200 && code <= 208) {
      flag = false;
    } else {
      flag = true;
    }
    weather.basic.flag = flag;


    //日期格式化
    for (let i = 0; i < weather.daily_forecast.length; i++) {
      weather.daily_forecast[i].date = tempObj.crtTimeFtt(weather.daily_forecast[i].date, "MM/dd");
    }
 
    this.data.templateSelect.push({
      selettype: "weather",//模版名称
      City: {
        DateValue: tempObj.crtTimeFtt(date, "yyyy/MM/dd"),
        weekday: weekday,
      },
      userInfo: app.globalData.userInfo,
      guidesInfo: this.data.guidesInfo,
      current: current,
      CityWeather: weather 
    });
    this.data.scrollTop = this.data.scrollTop + 385;
    this.setData({
      templateSelect: this.data.templateSelect,
      scrollTop: this.data.scrollTop

    })//页面传递值
  },
  closedConfirm: function () {
    this.setData({
      confirmStatus: false
    })
  },
  openConfirm: function () {
    this.setData({
      confirmStatus: true
    })
  },
  swiperChange: function (e) {
    this.setData({
      swiperCurrent: e.detail.current
    })
  },
  scrollEvent: function (e) {
    this.setData({
      scrollStatus: true
    })
  },
  scrollEndEvent: function () {
    if (this.data.scrollStatus) {
      this.setData({
        scrollStatus: false
      })
    }
  },
  godeitles(e){
    this.data.timerStatus = false;
    clearInterval(interval);
    this.audioCtx.pause();
    this.setData({
      playStatus: false
    })
    wx.navigateTo({
      url: '../spot/spot?spotId=' + e.currentTarget.dataset.spotid
    })
  },
  changebtn: function () {
    this.setData({
      btnStatus: true
    });
  },
  onHide:function(){
    clearInterval(interval);
    this.audioCtx.pause();
    this.setData({
      playStatus: false
    })
  },
  copyDownload: function () {
    let that = this;

    wx.setClipboardData({
      data: 'http://www.etoury.com',
      success: function (res) {
        that.setData({
          success: true,
          confirmStatus: false,
          guidesshow: "",
          btnStatus: false
        })
        setTimeout(function () {
          that.setData({
            success: false
          })
        }, 2000);
      }
    })
  }

})

